home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1990 / 05 / vgacolor.asm < prev    next >
Assembly Source File  |  1990-08-06  |  5KB  |  181 lines

  1. ;
  2. ; *** Listing 1 ***
  3. ;
  4. ; Program to demonstrate use of the DAC registers by selecting a
  5. ; smoothly contiguous set of 256 colors, then filling the screen
  6. ; with concentric diamonds in all 256 colors so that they blend
  7. ; into one another to form a continuum of color.
  8. ;
  9.         .model small
  10.     .stack    200h
  11.     .data
  12.  
  13. ; Table used to set all 256 DAC entries.
  14. ;
  15. ; Table format:
  16. ;    Byte 0: DAC register 0 red value
  17. ;    Byte 1: DAC register 0 green value
  18. ;    Byte 2: DAC register 0 blue value
  19. ;    Byte 3: DAC register 1 red value
  20. ;    Byte 4: DAC register 1 green value
  21. ;    Byte 5: DAC register 1 blue value
  22. ;            :
  23. ;    Byte 765: DAC register 255 red value
  24. ;    Byte 766: DAC register 255 green value
  25. ;    Byte 767: DAC register 255 blue value
  26.  
  27. ColorTable    label    byte
  28.  
  29. ; The first 64 entries are increasingly dim pure green.
  30. X=0
  31.     REPT    64
  32.     db    0,63-X,0
  33. X=X+1
  34.     ENDM
  35.  
  36. ; The next 64 entries are increasingly strong pure blue.
  37. X=0
  38.     REPT    64
  39.     db    0,0,X
  40. X=X+1
  41.     ENDM
  42.  
  43. ; The next 64 entries fade through violet to red.
  44. X=0
  45.     REPT    64
  46.     db    X,0,63-X
  47. X=X+1
  48.     ENDM
  49.  
  50. ; The last 64 entries are increasingly dim pure red.
  51. X=0
  52.     REPT    64
  53.     db    63-X,0,0
  54. X=X+1
  55.     ENDM
  56.  
  57.         .code
  58. Start:
  59.     mov    ax,0013h    ;AH=0 selects set mode function,
  60.                 ; AL=13h selects 320x200 256-color
  61.     int    10h        ; mode
  62.  
  63.                 ;load the DAC registers with the
  64.                 ; color settings
  65.     mov    ax,@data    ;point ES to the default
  66.     mov    es,ax        ; data segment
  67.     mov    dx,offset ColorTable
  68.                 ;point ES:DX to the start of the
  69.                 ; block of RGB three-byte values
  70.                 ; to load into the DAC registers
  71.     mov    ax,1012h    ;AH=10h selects set color function,
  72.                 ; AL=12h selects set block of DAC
  73.                 ; registers subfunction
  74.     sub    bx,bx        ;load the block of registers
  75.                 ; starting at DAC register #0
  76.     mov    cx,100h        ;set all 256 registers
  77.     int    10h        ;load the DAC registers
  78.  
  79.                 ;now fill the screen with
  80.                 ; concentric diamonds in all 256
  81.                 ; color attributes
  82.     mov    ax,0a000h    ;point DS to the display memory
  83.     mov    ds,ax        ; segment
  84.                 ;
  85.                 ;draw diagonal lines in the upper
  86.                 ; left quarter of the screen
  87.     mov    al,2        ;start with color attribute #2
  88.     mov    ah,-1        ;cycle down through the colors
  89.     mov    bx,320        ;draw top to bottom (distance from
  90.                 ; one line to the next)
  91.     mov    dx,160        ;width of rectangle
  92.     mov    si,100        ;height of rectangle
  93.     sub    di,di        ;start at (0,0)
  94.     mov    bp,1        ;draw left to right (distance from
  95.                 ; one column to the next)
  96.     call    FillBlock    ;draw it
  97.                 ;
  98.                 ;draw diagonal lines in the upper
  99.                 ; right quarter of the screen
  100.     mov    al,2        ;start with color attribute #2
  101.     mov    ah,-1        ;cycle down through the colors
  102.     mov    bx,320        ;draw top to bottom (distance from
  103.                 ; one line to the next)
  104.     mov    dx,160        ;width of rectangle
  105.     mov    si,100        ;height of rectangle
  106.     mov    di,319        ;start at (319,0)
  107.     mov    bp,-1        ;draw right to left (distance from
  108.                 ; one column to the next)
  109.     call    FillBlock    ;draw it
  110.  
  111.                 ;draw diagonal lines in the lower
  112.                 ; left quarter of the screen
  113.     mov    al,2        ;start with color attribute #2
  114.     mov    ah,-1        ;cycle down through the colors
  115.     mov    bx,-320        ;draw bottom to top (distance from
  116.                 ; one line to the next)
  117.     mov    dx,160        ;width of rectangle
  118.     mov    si,100        ;height of rectangle
  119.     mov    di,199*320    ;start at (0,199)
  120.     mov    bp,1        ;draw left to right (distance from
  121.                 ; one column to the next)
  122.     call    FillBlock    ;draw it
  123.                 ;
  124.                 ;draw diagonal lines in the lower
  125.                 ; right quarter of the screen
  126.     mov    al,2        ;start with color attribute #2
  127.     mov    ah,-1        ;cycle down through the colors
  128.     mov    bx,-320        ;draw bottom to top (distance from
  129.                 ; one line to the next)
  130.     mov    dx,160        ;width of rectangle
  131.     mov    si,100        ;height of rectangle
  132.     mov    di,199*320+319    ;start at (319,199)
  133.     mov    bp,-1        ;draw right to left (distance from
  134.                 ; one column to the next)
  135.     call    FillBlock    ;draw it
  136.  
  137.     mov    ah,1        ;wait for a key
  138.     int    21h        ;
  139.  
  140.     mov    ax,0003h    ;return to text mode
  141.     int    10h        ;
  142.  
  143.     mov    ah,4ch        ;done--return to DOS
  144.     int    21h
  145.  
  146. ; Fills the specified rectangular area of the screen with diagonal
  147. ; lines.
  148. ;
  149. ; Input:
  150. ;    AL = initial attribute with which to draw
  151. ;    AH = amount by which to advance the attribute from
  152. ;        one pixel to the next
  153. ;    BX = distance to advance from one pixel to the next
  154. ;    DX = width of rectangle to fill
  155. ;    SI = height of rectangle to fill
  156. ;    DS:DN = screen address of first pixel to draw
  157. ;    BP = offset from the start of one column to the start of
  158. ;        the next
  159.  
  160. FillBlock:
  161. FillHorzLoop:
  162.     push    di        ;preserve pointer to top of column
  163.     push    ax        ;preserve initial attribute
  164.     mov    cx,si        ;column height
  165. FillVertLoop:
  166.     mov    [di],al        ;set the pixel
  167.     add    di,bx        ;point to the next row in the column
  168.     add    al,ah        ;advance the attribute
  169.     loop    FillVertLoop    ;
  170.     pop    ax        ;restore initial attribute
  171.     add    al,ah        ;advance to the next attribute to
  172.                 ; start the next column
  173.     pop    di        ;retrieve pointer to top of column
  174.     add    di,bp        ;point to next column
  175.     dec    dx        ;have we done all columns?
  176.     jnz    FillHorzLoop    ;no, do the next column
  177.     ret            ;
  178.  
  179.         end    Start
  180.  
  181.